import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            char[] c = in.nextLine().toCharArray();
            int[] hash = new int[26];
            int type = 0;
            int maxLength = 0;
            for (int left = 0, right = 0; right < c.length; right++) {
                if (hash[c[right]-'a']++ == 0) {
                    type++;
                }
                if (type <= 2) {
                    maxLength = Math.max(maxLength, right-left+1);
                }
                while (left < right && type > 2) {
                    if (hash[c[left++]-'a']-- == 1) {
                        type--;
                    }
                }
            }
            System.out.println(maxLength);
        }
    }
}
